<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 *
 * @package     anime
 * @author      Do Ngoc Son (ngocson2306@gmail.com)
 * @copyright   PHP TEAM
 * @link        http://phpandmysql.net
 * @since       Version 1.0
 * @phone       0982644370
 *
 */
class Film_model extends MY_Model{
	public $table = 'film';
	public $key   = 'idphim';
	public function __construct(){
		parent:: __construct();
		
	}

  public function save($id=false,$data=array()){
  	if(!$id){
  		$this->insert($data);
  	}
  	$result = $this->update($id,$data);
  	if($result){
  		return $id;
  	}
  	return false;
  } 

  public function film_new($limit = false){
    $param           = array();
    $param['select'] = array('idphim','name','thumb','content','urlep_new','hot','decu','rewrite','likeFilm','viewed');
    $param['where']  = array('status' => 1);
    $param['order']  = array('timepost','DESC');
    if(!$limit){
      $param['limit']  = array(12);
    }else{
      $param['limit']  = array($limit);
    }
    return $this->get_list($param);
  }

  public function ratings_anime(){
    $param           = array();
    $param['select'] = array('idphim','name','likeFilm','viewed','rewrite');
    $param['where']  = array('status' => 1,'option_film !=' => 3);
    $param['order']  = array('viewed','DESC');
    $param['limit']  = array(12);
    return $this->get_list($param);
  }

  public function ratings_cartoon(){
    $param           = array();
    $param['select'] = array('idphim','name','likeFilm','viewed','rewrite');
    $param['where']  = array('status' => 1,'option_film' => 3);
    $param['order']  = array('viewed','DESC');
    $param['limit']  = array(12);
    return $this->get_list($param);
  }

  public function top_film(){
    $param           = array();
    $param['select'] = array('idphim','name','likeFilm','viewed','thumb','content','rewrite');
    $param['where']  = array('status' => 1);
    $param['order']  = array('viewed','DESC');
    $param['limit']  = array(5);
    return $this->get_list($param);
  }

  public function full_episode($limit=false,$start= false){
    $this->db->select('idphim,name,thumb,content,urlep_new,hot,decu,rewrite','urlep_new');
    $this->db->where('status',1);
    $this->db->where('option_film !=',3);
    $this->db->where('option_film !=',1);
    if($limit){
      $this->db->limit($limit,$start);
    }else{
      $this->db->limit(8);
    }
    return $this->db->get($this->table)->result_array();
  }

  public function total_fullepisode(){
    $this->db->select('idphim,name,thumb,content,urlep_new,hot,decu');
    $this->db->where('status',1);
    $this->db->where('option_film !=',3);
    $this->db->where('option_film !=',1);
    return $this->count_all();
  }

  public function slider(){
    $param           = array();
    $param['select'] = array('idphim','thumb','rewrite','big_thumb','content','name');
    $param['where']  = array('status' => 1);
    $param['order']  = array('timepost','DESC');
    $param['limit']  = array(7);
    return $this->get_list($param);
  }
}